package com.zzchangfu.service;

import com.zzchangfu.dto.Express;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ExpressService {


    @Tool(description = "用于查询我的快递",returnDirect = true)
    public List<Express> getExpress(@RequestParam(defaultValue = "") String state) {
        // 生成测试数据
        List<Express> data = getData();
        // 根据状态过滤（如果state为null或空则返回全部）
        return state == null || state.isEmpty()
                ? data
                : data.stream()
                .filter(e -> e.getState().equalsIgnoreCase(state))
                .collect(Collectors.toList());
    }

    @Tool(description = "用于查询年龄")
    public String getAge() {
        return "100";
    }

    /**
     * 生成测试快递数据
     */
    private List<Express> getData() {
        List<Express> data = new ArrayList<>();
        LocalDateTime now = LocalDateTime.now();
        data.add(new Express(1001L, "北京", "西安", now.minusDays(12), "已签收"));
        data.add(new Express(1002L, "广州", "西安", now.minusDays(12), "已签收"));
        data.add(new Express(1003L, "杭州", "西安", now.minusDays(3), "运送中"));
        data.add(new Express(1004L, "深圳", "西安", now.minusDays(3), "运送中"));
        data.add(new Express(1005L, "南京", "西安", now.minusDays(1), "待发货"));
        return data;
    }

}